﻿namespace HCMS.CommonDtos
{
    /// <summary>
    /// 分页参数 Dto
    /// </summary>
    public class PagerArgsDto
    {
        private int _currentPageIndex;
        /// <summary>
        /// 当前页码
        /// </summary>
        public int CurrentPageIndex
        {
            get
            {
                return _currentPageIndex;
            }
            set
            {
                if (value <= 0)
                {
                    value = 1;
                }
                _currentPageIndex = value;
            }
        }

        private int _pageSize;
        /// <summary>
        /// 每页记录数
        /// </summary>
        public int PageSize
        {
            get { return _pageSize; }
            set
            {
                if (value <= 0)
                {
                    value = 10;
                }
                _pageSize = value;
            }
        }

        /// <summary>
        /// 总页数
        /// </summary>
        private int PageCount { get; set; }

        private int _rowCount;
        /// <summary>
        /// 总记录数
        /// </summary>
        public int RowCount
        {
            get
            {
                return _rowCount;
            }

            set
            {
                _rowCount = value;

                if (PageSize == 0)
                {
                    PageSize = 10;
                }

                PageCount = RowCount % PageSize == 0 ?
                    RowCount / PageSize :
                    RowCount / PageSize + 1;

                if (CurrentPageIndex <= 0)
                {
                    CurrentPageIndex = 1;
                }
                else if (CurrentPageIndex > PageCount)
                {
                    CurrentPageIndex = PageCount;
                }
            }
        }

        /// <summary>
        /// 是否 启用 分页
        /// </summary>
        public bool IsPager { get; set; } = true;
    }
}
